package cn.math.appmath.action;

import java.util.Map;

import cn.math.appmath.biz.UserBiz;
import cn.math.appmath.entity.User;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
	private static final long serialVersionUID = -4565898601842133546L;
	public UserBiz userBiz;
	public String message;
	public User user;

	public String loginforward(){
		message = "";
		return SUCCESS;
	}
	
	public String login(){
		if(!userBiz.login(user)){
			message = "用户名或密码错误";
			user.setUname("");
			user.setUpassword("");
			return INPUT;
		}
		message = "";
		ActionContext ac = ActionContext.getContext();
		Map session = ac.getSession();
		session.put("login", user);
		return SUCCESS;
	}
	
	public String findUser(){
		user = userBiz.findUser();
		return SUCCESS;
	}
	
	public String updateUser(){
		if(userBiz.updateUser(user) != 0){
			message = "用户名或密码保存成功";
			return SUCCESS;
		}else{
			message = "用户名或密码保存失败";
			return INPUT;
		}	
	}

	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
